import { createApp } from 'vue';

import Cookies from 'js-cookie';

import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
import locale from 'element-plus/es/locale/lang/zh-cn';

import '@/assets/styles/index.scss'; // global css

import App from './App';
import store from './store';
import router from './router';
import directive from './directive'; // directive

// 注册指令
import plugins from './plugins'; // plugins

// svg图标
import 'virtual:svg-icons-register';
import SvgIcon from '@/components/SvgIcon';
import elementIcons from '@/components/SvgIcon/svgicon';

import './permission'; // permission control

import { useDict, useConstDict } from '@/utils/dict';
import {
  parseTime,
  resetForm,
  addDateRange,
  handleTree,
  selectDictLabel,
  selectDictLabels,
  addFieldTimeRange,
  addFieldDateRange,
  formatIndex,
} from '@/utils/base';

import Pagination from '@/components/Pagination';
import RightToolbar from '@/components/RightToolbar';
import Editor from '@/components/Editor';
import FileUpload from '@/components/FileUpload';
import ImageUpload from '@/components/ImageUpload';
import VideoUpload from '@/components/VideoUpload';
import DictTag from '@/components/DictTag';

import formCreate from '@form-create/element-ui';
import VForm3 from 'vform3-builds';
import 'vform3-builds/dist/designer.style.css';

// 完整导入 UI 组件库
import VxeUI from 'vxe-pc-ui';
import 'vxe-pc-ui/lib/style.css';
// 完整导入 表格库
import VxeUITable from 'vxe-table';
import 'vxe-table/lib/style.css';

const app = createApp(App);

app.config.globalProperties.useDict = useDict;
app.config.globalProperties.useConstDict = useConstDict;
app.config.globalProperties.parseTime = parseTime;
app.config.globalProperties.resetForm = resetForm;
app.config.globalProperties.handleTree = handleTree;
app.config.globalProperties.addDateRange = addDateRange;
app.config.globalProperties.addFieldTimeRange = addFieldTimeRange;
app.config.globalProperties.addFieldDateRange = addFieldDateRange;
app.config.globalProperties.selectDictLabel = selectDictLabel;
app.config.globalProperties.selectDictLabels = selectDictLabels;
app.config.globalProperties.formatIndex = formatIndex;

app.component('DictTag', DictTag);
app.component('Pagination', Pagination);
app.component('FileUpload', FileUpload);
app.component('VideoUpload', VideoUpload);
app.component('ImageUpload', ImageUpload);
app.component('RightToolbar', RightToolbar);
app.component('Editor', Editor);

app.use(router);
app.use(store);
app.use(plugins);
app.use(elementIcons);
app.component('SvgIcon', SvgIcon);
app.use(formCreate);
app.use(VForm3);
app.use(VxeUI);
app.use(VxeUITable);

directive(app);

app.use(ElementPlus, {
  locale: locale,
  size: Cookies.get('size') || 'default',
});

app.mount('#app');
